$(function () {
				$('#myTab a:first').tab('show');
				$('#myTab a').click(function (e) {
					e.preventDefault();
					$(this).tab('show');
				})
			})
$(document).ready(function(){
BackToTop({
		text : '^ Back to top',
		autoShow : true,
        autoShowOffset: 300,
		timeEffect : 800,
		appearMethod : 'fade',
		effectScroll : 'easeOutCubic', /** all effects http://jqueryui.com/docs/effect/#easing */
        opacity : 1,
        top: 1
	});

 //$("#messageDetails").hide();
 $("#othCateg").hide();
 $('#selectCatg').change(function() {
	  /**dropdown = $('#selectCatg').val();**/
	  $("#errorCatg").hide();
	  selectedText  = $("#selectCatg option:selected").text();
	   if (selectedText == 'Others')
		{
		    $("#othCateg").show();
		}
		else{
		 $("#othCateg").hide();
		}
		if (selectedText == 'Select Category'){
			 $("#errorCatg").show();
		}

	});
 $('.thumbnail').fancybox({
					openEffect  : 'none',
					closeEffect : 'none'
				});
 			
 $('.carousel').carousel({
                    interval: false
                });
 $("#messagesubmit").click(function() {
 	
 	var sendData = {
					name: $("#inputName").val(),
					email:$("#inputEmail").val(), 
					message:$("#inputMsg").val()
				};
	var url = $("#inputUrl").val();
	$.getJSON(url, sendData, function(data) {
					alert(data);
				});
				
 });
 $("#subscription").click(function(){
 		
 		var emailID = $("#subscriptionEmail").val();
 		var tUrl = $("#suburl").val();
 		if($("#subscriptionEmail").val() == "")
 			alert("Please fill the email address to subscribe our Newsletters");
 		else{

 			 if (!isValidEmailAddress(emailID)) {
				        alert('Please enter valid email address');
				        $("input#sc_email").focus();   //focus on email field
				        return false;  
				    }
 			var msgData={
 				'emailID' : emailID
 			}
 			$.ajax({
						type: "post",
						url: tUrl,
						cache: false,
						data: msgData,
						dataType: "json",
						success: function(data) {
							//clear the email text box
							var a = document.getElementById("subscriptionEmail");
							a.value = a.defaultValue;
							alert(data.result);
							
						},
						error: function(request, status, error) {
					         alert(request.responseText);
				        }
					});
 		}
 	});
	//send broadcast message
 $("#broadcast").click(function() {
				var uid = $("#userid").val();
				var tUrl = $("#url").val();

				if (($("#subject").val() == "") || ($("#body").val() == ""))
					alert("Please fill all fields to send a broadcast message to portal users.");
				else {
					var msgData = {
						'userid': uid,
						'subject': $("#subject").val(),
						'body': $("#body").val()
					}
					$.ajax({
						type: "post",
						url: tUrl+"broadcastAllUsers",
						cache: false,
						data: msgData,
						success: function(data) {
							var obj = $.parseJSON(data);
							alert(data);
							addNewBroadcast(obj);	
						}
					});
					
				}
	});
 var light = null;
 $("#msgTable tr").click(function() {
 	
	$(this).addClass('selectedRowColor').siblings().removeClass("selectedRowColor");
	 //$(this).toggleClass("selectedRowColor");
    var bid = $(this).attr("id");
    alert($(this).attr("id"));
	var burl = $('#url').val();
	if (bid){
		var msgData = {
						'id': bid
					}
					$.ajax({
						type: "post",
						url: burl,
						cache: false,
						data: msgData,
						success: function(data) {
							var obj = $.parseJSON(data);
							$("#messageDetails").show();
							$('#subject').text(obj[0].subject);
							$('#messagebody').text(obj[0].body);	
						}
					});
	}
 });
function displayPropertyMap(lat, log){
	 var mapCanvas = document.getElementById('property_map_addr');
     var mapOptions = {
      center: new google.maps.LatLng(44.5403, -78.5463),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(mapCanvas, mapOptions)
   	var marker1 = new google.maps.Marker({
			position: new google.maps.LatLng(lat,log),
			map: map
		});
		
	}
});
 

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
};
 // add initial list of trips from database
// add trip list to UI page
function addNewBroadcast(blist) {
	$("#broadcastlist").find("tr:gt(0)").remove();
	var allrows;
	$.each(blist, function(index, bc) {
		allrows += '<tr id="' + bc.id + '">';
		allrows += '<td><div class="span2"><div class="triplistname">' + (index + 1) + '</div></div></td>';
		allrows += '<td><div class="span2"><div class="triplistname">' + bc.subject + '</div></div></td>';
		allrows += '<td><div class="span1"><div class="triplistsdate">' + bc.posted + '</div></div></td>';
		allrows += '<td><div class="span2">';
		allrows += ' <a class="trip btn">\></a></div></td></tr>';
	});
	$('#broadcastlist tr:last').after(allrows);
		}



